from django.db import models

# Create your models here.

class User(models.Model):

    gender = (
        ('male', "男"),
        ('female', "女"),
    )

    user_teams = (
        ('FA6A', "FA6A"),
        ('FA6B', "FA6B"),
        ('FA6C', "FA6C"),
        ('FA6D', "FA6D"),
        ('FA6_1', "FA6_1"),
        ('FA6_2', "FA6_2"),
        ('FA6CQ', "FA6CQ"),
    )

    user_position = (
        ('manager', "经理"),
        ('team leader', "组长"),
        ('member', "员工"),
        ('expert', "专家"),
    )

    user_groups = (
        ('admin', "管理员"),
        ('nomal_user', "普通用户"),
        ('power_user', "高级用户"),
    )

    name = models.CharField(max_length=128, unique=True)
    password = models.CharField(max_length=256)
    email = models.EmailField(unique=True)
    sex = models.CharField(max_length=32, choices=gender, default="女")
    department = models.CharField(max_length=128)
    sub_department = models.CharField(max_length=128)
    team = models.CharField(max_length=128, choices=user_teams)
    position = models.CharField(max_length=128, choices=user_position)
    group = models.CharField(max_length=128, choices=user_groups)
    c_time = models.DateTimeField(auto_now_add=True)
    has_confirmed = models.BooleanField(default=False)

    def __str__(self):
        return self.name
    
    class Meta:
        ordering = ["-c_time"]
        verbose_name = "用户"
        verbose_name_plural = "用户"


class ConfirmString(models.Model):
    code = models.CharField(max_length=256)
    user = models.OneToOneField('User', on_delete=models.CASCADE)
    c_time = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.user.name + ":  " + self.code
    
    class Meta:
        ordering = ["-c_time"]
        verbose_name = "确认码"
        verbose_name_plural = "确认码"
